package com.example.xinwenkehuduan;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import cn.bmob.v3.Bmob;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;

public class ResActivity extends AppCompatActivity {
    private EditText etResUser;
    private EditText etResPass;
    private Button btnResOk;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_res);
        setTitle("注册页面");


        etResUser = findViewById(R.id.ed_resUser);
        etResPass = findViewById(R.id.ed_resPass);
        btnResOk = findViewById(R.id.btn_resOk);


        btnResOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                BmobUser bmobUser = new BmobUser();
                bmobUser.setUsername(etResUser.getText().toString());
                bmobUser.setPassword(etResPass.getText().toString());

                bmobUser.signUp(new SaveListener<BmobUser>() {
                    @Override
                    public void done(BmobUser bmobUser, BmobException e) {
                        if (e==null){
                            Toast.makeText(ResActivity.this,"注册成功",Toast.LENGTH_SHORT).show();
                            finish();
                        }
                    }
                });
            }
        });
    }
}
